/* GUI CONVERTED from ecmt09.p (converter v1.76) Tue Dec 31 20:31:56 2002 */
/* ecmt09.p - ECN MAINTENANCE Where Used Copy                             */
/* Copyright 1986-2002 QAD Inc., Carpinteria, CA, USA.                    */
/* All rights reserved worldwide.  This is an unpublished work.           */
/* $Revision: 1.7.1.6 $                                                           */
/*V8:ConvertMode=Maintenance                                              */
/* REVISION: 7.4      LAST MODIFIED: 07/01/93   BY: pma *H013*            */
/* REVISION: 7.4      LAST MODIFIED: 05/03/94   BY: qzl *H362*            */
/* REVISION: 7.4      LAST EDIT: 05/14/94   BY: QZL     *H370* sr101810   */
/* REVISION: 7.4      LAST EDIT: 10/27/94   MODIFIED BY: ame *H578*       */
/* REVISION: 7.4      LAST EDIT: 11/15/94   BY: qzl     *H596*            */
/* REVISION: 7.4      LAST EDIT: 02/08/95   BY: cpp     *H0B7*            */
/* REVISION: 7.4      LAST EDIT: 12/30/95   BY: jzs     *H0HM*            */
/* REVISION: 7.4      LAST EDIT: 12/30/95   BY: qzl     *H0J1*            */
/* REVISION: 8.6      LAST EDIT: 06/06/96   BY: Mariya Kutwal *K00C*      */
/* REVISION: 8.6      LAST EDIT: 02/27/97   BY: *H0SY*  Russ Witt         */
/* REVISION: 8.6      LAST MODIFIED: 08/13/97   BY: Joe Gawel    *K0H5*   */

/* REVISION: 8.6E     LAST MODIFIED: 02/23/98   BY: *L007* A. Rahane      */
/* REVISION: 8.6E     LAST MODIFIED: 05/20/98   BY: *K1Q4* Alfred Tan     */
/* REVISION: 8.6E     LAST MODIFIED: 07/14/98   BY: *J2RV* Niranjan R.    */
/* REVISION: 9.0      LAST MODIFIED: 01/03/00   BY: *K24Y* Rajesh Thomas  */
/* REVISION: 9.1      LAST MODIFIED: 03/24/00 BY: *N08T* Annasaheb Rahane */
/* REVISION: 9.1      LAST MODIFIED: 08/14/00 BY: *N0KW* Jacolyn Neder    */
/* Old ECO marker removed, but no ECO header exists *F0PN*                */
/* $Revision: 1.7.1.6 $    BY: Shoma Salgaonkar      DATE: 12/30/02  ECO: *N230*  */

/*hk-s-010                  by: mage             date: 12/30/03                */
/******************************************************************************/
/* All patch markers and commented out code have been removed from the source */
/* code below. For all future modifications to this file, any code which is   */
/* no longer required should be deleted and no in-line patch markers should   */
/* be added.  The ECO marker should only be included in the Revision History. */
/******************************************************************************/

{mfdeclre.i}
/* EXTERNAL LABEL INCLUDE */
{gplabel.i}

{ecmtparm.i}

/* SCROLLING WINDOW VARIABLES */
{wndvar2.i}

define variable comp     like ps_comp                                  no-undo.
define variable level    as   integer                                  no-undo.
define variable maxlevel as   integer     format ">>>"  label "Levels" no-undo.
define variable eff_date like ar_effdate                               no-undo.
define variable parent   like ps_par                                   no-undo.
define variable desc1    like pt_desc1                                 no-undo.
define variable um       like pt_um                                    no-undo.
define variable phantom  like mfc_logical format "yes"  label "Ph"     no-undo.
define variable iss_pol  like pt_iss_pol  format "/no"                 no-undo.
define variable record   as   integer extent 100                       no-undo.
define variable lvl      as   character   format "x(7)" label "Level"  no-undo.
define variable ecmid    like wo_lot                                   no-undo.
define variable dbase    like si_db                                    no-undo.
define variable rev      like pt_rev                                   no-undo.

define buffer ecmmstr for ecm_mstr.

/* SWAPPED THE FUNCTIONING OF parent AS IT WAS USED FOR THE PURPOSE OF comp */
/* I.E. RENAMED comp TO parent AND VICE-VERSA                               */

/* WORKFILE pswkfl IS REPLACED  BY A TEMP-TABLE */
/* CHANGED pscomp WITH pspar */
define temp-table pswkfl
   field psstar  as   character format "x(1)"
   field pslvl   like lvl
   field pspar   like ps_comp   label "Parent Item"
   field psdesc  like desc1
   field psref   like ps_ref
   field psrecid as   recid.

find ecm_mstr
   where recid(ecm_mstr) = ecm_recid
   exclusive-lock no-error no-wait.

if locked(ecm_mstr)
then do:
   /* RECORD LOCKED BY ANOTHER USER, TRY LATER */
   assign
      msgnbr  = 7422
      warnlvl = 4.
   return.
end. /* IF locked(ecm_mstr) */

if not available (ecm_mstr)
then do:
   /* PROCESS NOT COMPLETE */
   assign
      msgnbr  = 5630
      warnlvl = 2.
   return.
end. /* IF NOT AVAILABLE (ecm_mstr) */

eff_date = today.

FORM /*GUI*/ 
   space(1)
   comp label "Component Item"
   desc1
   um
   eff_date
   rev
   maxlevel
with frame ecmt09a width 80 attr-space no-underline
   title color normal (getFrameTitle("WHERE_USED_COPY",23)) THREE-D /*GUI*/.


/* SET EXTERNAL LABELS */
setFrameLabels(frame ecmt09a:handle).

/* SET COMPONENT TO GLOBAL PART NUMBER */
comp        = global_part.
repeat with frame ecmt09a:
/*GUI*/ if global-beam-me-up then undo, leave.

   maxlevel = 1.
   pause 0.

   for each pswkfl exclusive-lock:
      delete pswkfl.
   end. /* FOR EACH pswkfl */

   update
      comp
      eff_date
      rev
      maxlevel with frame ecmt09a
   editing:

      if frame-field = "comp"
      then do:
         /* FIND NEXT/PREVIOUS RECORD */
         /* CHANGED SECOND AND FOURTH PARAMETER FROM parent TO comp */
         {mfnp.i ps_mstr
                 comp
                 ps_comp
                 comp
                 ps_comp
                 ps_comp}

         if recno <> ?
         then do:
            assign
               comp  = ps_comp
               desc1 = "".

            for first pt_mstr
               fields (pt_desc1 pt_iss_pol pt_part pt_phantom pt_um)
               where pt_part = comp
               no-lock:
            end. /* FOR FIRST pt_mstr */

            if available pt_mstr
            then
               desc1 = pt_desc1.

            if not available pt_mstr
            then do:

               for first bom_mstr
                  fields (bom_batch bom_batch_um bom_desc bom_parent)
                  where bom_parent = comp
                  no-lock:
               end. /* FOR FIRST bom_mstr */

               if available bom_mstr
               then
                  desc1 = bom_desc.
            end. /* IF NOT AVAILABLE pt_mstr */

            display
               comp
               desc1
            with frame ecmt09a.
            recno = ?.
         end. /* If recno <> ? */

      end. /* IF FRAME-FIELD = "comp" */

      else do:
         status input.
         readkey.
         apply lastkey.
      end. /* ELSE DO */

   end. /* EDITING BLOCK */

   if rev <> ""
   then do:
      for each ecmmstr no-lock
         where  ecm_eff_date <> ?,
          each  ecd_det no-lock
          where  ecd_nbr    = ecmmstr.ecm_nbr
            and ecd_new_rev = rev
      break by
      ecm_eff_date
      descending:

         if ecd_part = comp
         then do:

            eff_date = ecm_eff_date.
            leave.
         end. /* IF ecd_part = comp */

      end. /* FOR EACH ecmmstr */

   end. /* If rev <> "" */

   assign
      desc1 = ""
      um    = "".

   assign
      comp.

   for first pt_mstr
      fields (pt_desc1 pt_iss_pol pt_part pt_phantom pt_um)
      where pt_part = comp
      use-index pt_part
      no-lock:
   end. /* FOR FIRST pt_mstr */

   if not available pt_mstr
   then do:

      for first bom_mstr
         fields (bom_batch bom_batch_um bom_desc bom_parent)
         where bom_parent = comp
         no-lock:
      end. /* FOR FIRST bom_mstr */

      if not available bom_mstr
      then do:

         hide message no-pause.
         /* ITEM NUMBER DOES NOT EXIST */
         {pxmsg.i &MSGNUM=17 &ERRORLEVEL=3}

         display
            desc1
            um with frame ecmt09a.
         pause.
         undo, retry.
      end. /* IF NOT AVAILABLE bom_mstr */

      assign
         um    = bom_batch_um
         desc1 = bom_desc
         comp  = bom_parent.
   end. /* IF NOT AVAILABLE pt_mstr */

   else
      assign
         desc1 = pt_desc1
         um    = pt_um
         comp  = pt_part.

   display
      comp
      desc1
      um.

   assign
      level    = 0
      parent   = comp
      maxlevel = min(maxlevel,99)
      repaint  = yes
      level    = 1.

      for first ps_mstr
       fields (ps_batch_pct ps_comp ps_default ps_end ps_fcst_pct ps_group
              ps_item_no ps_lt_off ps_mandatory ps_op ps_par ps_process
              ps_ps_code ps_qty_per ps_qty_per_b ps_qty_type ps_ref
              ps_rmks ps_scrp_pct ps_start)
              where ps_comp = comp 
       use-index ps_comp
      no-lock:
    end. /* FOR FIRST ps_mstr */

   repeat:

      if not available ps_mstr
      then do:
         repeat:
            level = level - 1.
            if level < 1
            then
               leave.

            for first ps_mstr
               fields (ps_batch_pct ps_comp ps_default ps_end ps_fcst_pct
                       ps_group ps_item_no ps_lt_off ps_mandatory ps_op
                       ps_par ps_process ps_ps_code ps_qty_per ps_qty_per_b
                       ps_qty_type ps_ref ps_rmks ps_srp_pct ps_start)
               where recid(ps_mstr) = record[level]
               no-lock:
            end. /* FOR FIRST ps_mstr */

            comp = ps_comp.
            find next ps_mstr use-index ps_comp
               where ps_comp = comp
               no-lock no-error.

            if available ps_mstr
            then
               leave.
         end. /* REPEAT BLOCK */

      end. /* IF NOT AVAILABLE ps_mstr */

      if level < 1
      then
         leave.

      if  eff_date =  ? or
         (eff_date <> ? and
         (ps_start =  ? or
          ps_start <= eff_date) and
         (ps_end    =  ? or
          eff_date <= ps_end))
      then do:

         assign
            desc1   = ""
            um      = ""
            iss_pol = no
            phantom = no.

         for first pt_mstr
            fields (pt_desc1 pt_iss_pol pt_part pt_phantom pt_um)
            where pt_part = ps_par
            no-lock:
         end. /* FOR FIRST pt_mstr */

         if available pt_mstr
         then
            assign
               desc1   = pt_desc1
               um      = pt_um
               iss_pol = pt_iss_pol
               phantom = pt_phantom.

         else do:
            for first bom_mstr
               fields (bom_batch bom_batch_um bom_desc bom_parent)
               where bom_parent = ps_comp
               no-lock:
            end. /* FOR FIRST bom_mstr */

            if available bom_mstr
            then
               assign
                  um    = bom_batch_um
                  desc1 = bom_desc.
         end. /* ELSE DO */

         assign
            record[level] = recid(ps_mstr)
            lvl           = "......."
            lvl           = substring(lvl,1,min(level - 1,6)) + string(level).

         if length(lvl) > 7
         then
            lvl = substring(lvl,length(lvl) - 6,7).

         create pswkfl.

         do:
            assign
               psrecid = recid(ps_mstr)
               pslvl   = lvl
               pspar   = ps_par
               psdesc  = desc1
               psref   = ps_ref.
         end. /* DO BLOCK */

         if level       < maxlevel
            or maxlevel = 0
         then do:
            assign
               comp  = ps_par
               level = level + 1.

            for first ps_mstr
               fields (ps_batch_pct ps_comp ps_default ps_end ps_fcst_pct
                       ps_group ps_item_no ps_lt_off ps_mandatory ps_op
                       ps_par ps_process ps_ps_code ps_qty_per ps_qty_per_b
                       ps_qty_type ps_ref ps_rmks ps_scrp_pct ps_start)
               where ps_comp = comp
               use-index ps_comp
               no-lock:
            end. /* FOR FIRST ps_mstr */

         end. /* IF level < maxlevel OR ... */

         else do:
            find next ps_mstr use-index ps_comp
               where ps_comp = comp
               no-lock no-error.
         end. /* ELSE DO */

      end. /* If eff_date = ? OR ... */

      else do:
         find next ps_mstr use-index ps_comp
            where ps_comp = comp
            no-lock no-error.
      end. /* ELSE DO */

   end. /* REPEAT BLOCK */

   assign
      window_row  = 10
      window_down = 8.

   pause 0.
  
   /*hk-s-010   **********add **************************/
   FOR EACH pswkfl :
      FIND bom_mstr WHERE bom_parent = pspar AND bom__chr01 = ecm_user1 NO-LOCK NO-ERROR.
      IF NOT AVAILABLE bom_mstr  THEN DELETE pswkfl.
   END.
   /*hk-s-010   **********add **************************/

   /* CHANGED SECOND, THIRD AND FOURTH PARAMETERS FROM pscomp TO pspar */
   {windowx.i
      &file        = pswkfl
      &display     = "psstar no-label pslvl pspar psdesc psref"
      &index-fld1  = pspar
      &index-fld2  = pspar
      &frametitle  = """"
      &framephrase = "width 80"
      &return      = no
      &recid-var   = global_recid
      &tag-var     = psstar
      &tag-val1    = ""*""
      &tag-val2    = """"
      &tag-all     = no
      }

   if keyfunction(lastkey) = "GO" or
      lastkey              = keycode("RETURN")
   then do:
      /* PROCESS NOT COMPLETE */
      assign
         msgnbr = 5630
         warnlvl = 2.

      for each pswkfl
         where psstar = "*":

         for first ps_mstr
            fields (ps_batch_pct ps_comp ps_default ps_end ps_fcst_pct ps_group
                    ps_item_no ps_lt_off ps_mandatory ps_op ps_par ps_process
                    ps_ps_code ps_qty_per ps_qty_per_b ps_qty_type ps_ref
                    ps_rmks ps_scrp_pct ps_start)
            where recid(ps_mstr) = psrecid
            no-lock:
         end. /* FOR FIRST ps_mstr */

         if available ps_mstr
         then do:

            for first bom_mstr
               fields (bom_batch bom_batch_um bom_desc bom_parent)
               where bom_parent = ps_par
               no-lock:
            end. /* FOR FIRST bom_mstr */

            for first ecd1_det
               fields (ecd1_batch ecd1_batch_pct ecd1_batch_um ecd1_comp
                       ecd1_fcst_pct ecd1_group ecd1_item_no ecd1_lt_off
                       ecd1_nbr ecd1_op ecd1_par ecd1_process ecd1_psprocess
                       ecd1_qty_per ecd1_qty_per_b ecd1_qty_type ecd1_ref
                       ecd1_rmks ecd1_scrp_pct ecd1__qad01 ecd1__qad02
                       ecd1__qad03 ecd1__qad04 ecd1__qad05)
               where ecd1_nbr  = ecm_nbr
               and   ecd1_par  = ps_par
               and   ecd1_comp = ps_comp
               and   ecd1_ref  = ps_ref
               exclusive-lock:
            end. /* FOR FIRST ecd1_det */

            if not available ecd1_det
            then do:
               create ecd1_det.
               assign
                  ecd1_nbr       = ecm_nbr
                  ecd1_par       = ps_par
                  ecd1_comp      = ps_comp
                  ecd1_ref       = ps_ref
                  ecd1_batch_pct = ps_batch_pct
                  ecd1_item_no   = ps_item_no
                  ecd1_op        = ps_op
                  ecd1_qty_per   = ps_qty_per
                  ecd1_qty_per_b = ps_qty_per_b
                  ecd1_qty_type  = ps_qty_type
                  ecd1_rmks      = ps_rmks
                  ecd1_scrp_pct  = ps_scrp_pct
                  ecd1_batch     = 1
                  ecd1_process   = "T-14"
                  ecd1__qad01    = no
                  ecd1__qad02    = ps_start
                  ecd1__qad03    = ps_ps_code
                  ecd1__qad04    = string(integer(ps_mandatory))
                  ecd1__qad05    = string(integer(ps_default))
                  ecd1_lt_off    = ps_lt_off
                  ecd1_fcst_pct  = ps_fcst_pct
                  ecd1_group     = ps_group
                  ecd1_psprocess = ps_process.

               if available bom_mstr
                  and bom_batch <> 0
                  and bom_batch <> 1
               then
                  assign
                     ecd1_batch    = bom_batch
                     ecd1_batch_um = bom_batch_um.

               if recid(ecd1_det)  = -1
               then .

            end. /* IF NOT AVAILABLE ecd1_det */

         end. /* IF AVAILABLE ps_mstr */

      end. /* FOR EACH pswkfl*/

      do on endkey undo, leave:
         /* PROCESS COMPLETE */
         {pxmsg.i &MSGNUM=1107 &ERRORLEVEL=1}
         pause.
      end. /* DO ON ENDKEY */

      assign
         msgnbr  = 0
         warnlvl = 1.
   end. /*IF KEYFUNCTION(LASTKEY) = GO ... */

   else apply lastkey.
end. /* REPEAT BLOCK */
